package com.example.readbook.UI.Act

import android.annotation.SuppressLint
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.example.readbook.R
import com.example.readbook.Sql.JournalUtils
import com.example.readbook.UI.BaseUI.BaseActivity
import com.example.readbook.Utils.StringUtils
import com.example.readbook.Utils.Utils
import kotlinx.android.synthetic.main.act_write_journal_entry.*

/**
 * Package    : com.example.readbook.UI.Act
 * ClassName  : WriteJournalEntryActivity
 * Description: $写指定书籍的读后感
 * Date       : 2019/3/26 13:20
 */
class WriteSpecifiedActivity : BaseActivity() {
    var chooseBookName = ""

    override fun getLayoutResID(): Int {
        return R.layout.act_write_journal_entry
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        title = "写读后感"
        Act_Write_Spinn.visibility = View.GONE
        Act_Write_End.visibility = View.GONE
        Act_Write_Title.text = "读《" + intent.getStringExtra(StringUtils.BookName) + "》有感"
        chooseBookName = intent.getStringExtra(StringUtils.BookName)
        intent.getStringExtra("read").also {
            if (!it.isNullOrEmpty())
                Act_Write_Edit.setText(it)
        }
    }

    override fun initListener() {

    }

    override fun initData() {

    }

    //右上角菜单点击事件监听
    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == R.id.save) {
            if (Act_Write_Edit.text.toString().isEmpty()) {
                Utils.showToast("读后感还没有写哦～")
                return true
            }
            JournalUtils.getInstence(this@WriteSpecifiedActivity)
                    .addJournal(chooseBookName, Act_Write_Edit.text.toString())
            mActivity.finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }

    //加载右上角菜单
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.write, menu)
        return super.onCreateOptionsMenu(menu)
    }
}
